<?php

namespace App\Http\Controllers\Home\Goods;

use DB;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Redis;
use App\Http\Controllers\Home\Goods\Api\GoodsApi;
use App\Model\Goods;


class GoodsController extends Controller
{
    public function detail($gid)
    {   
        DB::table('goods')->where('id', $gid)->increment('click');
        $gooddata = Goods::select('state', 'id')->where('id', $gid)->first();
        if(empty($gooddata->id)){
            return view('Home/Goods/errorinfo');
        }
        $gooddata = Goods::select('state', 'id')->where('id', $gid)->first();
        if($gooddata->state == '2'){
            return view('Home/Goods/errorinfo');
        }

        $goodsApi = new GoodsApi();
        $onedata = $goodsApi->details($gid);//单个产品数据
 		$loadHotSale = $goodsApi->loadHotSale();//店长推荐
 		$goodsort = $goodsApi->goodSort();//商品分类
 		$shopHotSale = $goodsApi->shopHotSale();//店铺热销
        $detailHotSale = $goodsApi->detailShopHotSale();
 		// dd($onedata,$loadHotSale,$goodsort,$shopHotSale);
 		$o =[];
 		$c =[];
 		foreach($onedata->goods_price as $v){
 			$o[] = $v->color;
 			$c[] = $v->size;
 			$color = array_unique($o); 
 			$size = array_unique($c); 
 		}
 		
 		// dd($size,$color);
    	return view('Home/Goods/goods_detail', [
				    		'onedata' => $onedata, 
				    		'loadHotSale' => $loadHotSale, 
				    		'goodsort' =>$goodsort,
				    		'shopHotSale' =>$shopHotSale,
                            'detailHotSale' =>$detailHotSale,
				    		'color'=>$color,
				    		'size'=>$size,
                            ]
				    		);
    }
}